package DFSTest;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;

public class TestDemo2 {
    public static int count = 0;
    /**
     计算每个数字的数位和
     */
    public static int calNum(int i) {
        int sum = 0;
        while (i > 0) {
            sum += i % 10;
            i /= 10;
        }
        return sum;

    }
    /**
     i---->表示当前所在的行
     j---->表示当前所在的列
     */
    public static void dfs(int threshold, int i, int j, int rows, int cols,
                    boolean[][] b) {
        if (i < 0 || i >= rows || j < 0 || j >= cols ||
                b[i][j] == true/*当前节点是否被访问过*/ ) return ;
        if (calNum(i) + calNum(i) > threshold) return;
        //走到这里就代表这个点可以
        count++;
        b[i][j] = true;
        dfs(threshold, i + 1, j, rows, cols, b);
        dfs(threshold, i - 1, j, rows, cols, b);
        dfs(threshold, i, j + 1, rows, cols, b);
        dfs(threshold, i, j - 1, rows, cols, b);

    }
    public static int movingCount(int threshold, int rows, int cols) {
        if (threshold == 0)return 1;
        boolean[][] b = new boolean[rows][cols];
        dfs(threshold, 0, 0, rows, cols, b);
        return count;

    }

    public static void main(String[] args) {
    }
}
